package com.tbit.main.controller;

import com.tbit.main.common.JsonResult;
import com.tbit.main.pojo.AccountUser;
import com.tbit.main.pojo.AccountUserSug;
import com.tbit.main.service.AccountService;
import com.tbit.main.service.AccountUserSugService;
import com.tbit.main.service.TokenService;
import com.tbit.main.util.Assert;
import com.tbit.main.util.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 运维人员反馈
 *
 * @author LMY
 * @create 2021-06-29 13:53
 */
@RestController
@RequestMapping("/accountUserSug")
public class AccountUserSugController {

    @Autowired
    private TokenService tokenService;
    @Autowired
    private AccountUserSugService accountUserSugService;
    @Autowired
    private AccountService accountservice;

    /**
     * 添加
     *
     * @param token
     * @param accountUserSug
     * @return
     */
    @RequestMapping("/insert")
    public JsonResult insert(String token, AccountUserSug accountUserSug) {
        Assert.notNull(accountUserSug.getTitle(), "AccountUserSug.title.notNull");
        Assert.notNull(accountUserSug.getContent(), "AccountUserSug.content.notNull");


        AccountUser accountUser = tokenService.getAccount(token);

        accountUserSug.setAccountUserId(accountUser.getAccountUserId());
        accountUserSug.setAddTime(DateTimeUtil.getNowTime());
        accountUserSug.setAccountId(accountservice.getByAccountAndType(accountUser.getAccountId(), 1).getAccountId());
        accountUserSugService.insert(accountUserSug);

        return JsonResult.succ();
    }
}
